package com.example.photography.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.fastjson.JSONObject;
import com.example.photography.R;
import com.example.photography.bean.Product_bean;
import com.example.photography.bean.Product_contentBean;
import com.example.photography.bean.UrlBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public abstract class Label_ProtoAdapter extends RecyclerView.Adapter<Label_ProtoAdapter.ViewHolder> {
    private List<Product_bean.LabelBean> label;
    private Context context;

    public Label_ProtoAdapter(List<Product_bean.LabelBean> label, Context context) {
        this.label = label;
        this.context = context;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_photolabel, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Product_bean.LabelBean labelBean = label.get(position);
        List<UrlBean> urlBeans = JSONObject.parseArray(labelBean.getCover(), UrlBean.class);
        holder.svCover.setImageURI(urlBeans.get(0).getUrl());
        holder.tvGroup.setText("#" + labelBean.getLab_id() + "#");
        holder.tvFans.setText(labelBean.getFans() + "已关注");
        holder.rlLab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onclick(labelBean.getLab_id());
            }
        });
    }

    @Override
    public int getItemCount() {
        return label == null ? 0 : label.size();
    }


    static
    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.sv_cover)
        SimpleDraweeView svCover;
        @BindView(R.id.tv_group)
        TextView tvGroup;
        @BindView(R.id.tv_fans)
        TextView tvFans;
        @BindView(R.id.rl_lab)
        RelativeLayout rlLab;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
    protected abstract void onclick(String lab_id);
}
